# -*- coding:utf-8 -*-
# __auther__='jiangkai'

import os
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep


class UploadPic:
    def __init__(self, driver,btnlj=None, picpath=None,browertype="ie"):

        self.driver = driver

        # 双击
        ActionChains(driver).double_click(driver.find_element_by_xpath(btnlj)).perform()

        # 单击
        # if btnlj is not None:
        #     driver.find_element_by_xpath(btnlj).click()

        if browertype == "ie":
            os.system(os.getcwd() + "\\openDiagFrame.exe " + "选择要加载的文件 " + os.getcwd() + "\\" + picpath)
        else:
            os.system(os.getcwd() + "\\openDiagFrame.exe " + "文件上传 " + os.getcwd() + "\\" + picpath)
        # try:
        #     os.system(os.getcwd() + "\\openDiagFrame.exe " + "选择要加载的文件 " + os.getcwd() + "\\" + picpath)
        # except:
        #     os.system(os.getcwd() + "\\openDiagFrame.exe " + "文件上传 " + os.getcwd() + "\\" + picpath)

        sleep(1)

    def upfile(self, btnupf):
        if btnupf is not None:
            self.driver.find_element_by_xpath(btnupf).click()
